using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using QL_Truong_Hoc.DTO;

namespace QL_Truong_Hoc.DAO
{
	public static class TThiTotNghiepHocSinhDAO
	{
		#region Methods

		/// <summary>
		/// Saves a record to the tThiTotNghiepHocSinh table.
		/// </summary>
		public static bool Insert(Database objDb, DbTransaction objTrans, TThiTotNghiepHocSinhDTO tThiTotNghiepHocSinh)
		{
bool blnResult = false;
try
{
			clsValidationUtility.ValidateArgument("tThiTotNghiepHocSinh", tThiTotNghiepHocSinh);

			object[] parameters = new object[]
			{
				Null.GetNull(tThiTotNghiepHocSinh.TTN_ID, DBNull.Value),
				Null.GetNull(tThiTotNghiepHocSinh.HS_ID, DBNull.Value)
			};

int intResult;
if (objTrans == null)
{ intResult = objDb.ExecuteNonQuery("tThiTotNghiepHocSinhInsert", parameters); }
else if (objTrans.Connection == null)
{ intResult = objDb.ExecuteNonQuery("tThiTotNghiepHocSinhInsert", parameters); }
else
{ intResult = objDb.ExecuteNonQuery(objTrans, "tThiTotNghiepHocSinhInsert", parameters); }
if (intResult > 0) return true;
}
catch { return false; }
return blnResult;
		}

		/// <summary>
		/// Deletes a record from the tThiTotNghiepHocSinh table by its primary key.
		/// </summary>
		public static bool Delete(Database objDb, DbTransaction objTrans, int tTN_ID, int hS_ID)
		{
bool blnResult = false;
try
{
			object[] parameters = new object[]
			{
Null.GetNull(tTN_ID, DBNull.Value),
Null.GetNull(hS_ID, DBNull.Value)
			};

int intResult;
if (objTrans == null)
{ intResult = objDb.ExecuteNonQuery("tThiTotNghiepHocSinhDelete", parameters); }
else if (objTrans.Connection == null)
{ intResult = objDb.ExecuteNonQuery("tThiTotNghiepHocSinhDelete", parameters); }
else
{ intResult = objDb.ExecuteNonQuery(objTrans, "tThiTotNghiepHocSinhDelete", parameters); }
if (intResult > 0) return true;
}
catch { return false; }
return blnResult;
		}

		/// <summary>
		/// Deletes a record from the tThiTotNghiepHocSinh table by its primary key.
		/// </summary>
		public static bool Delete(Database objDb, DbTransaction objTrans, string strWhere)		{
bool blnResult = false;
try
{
			object[] parameters = new object[]
			{strWhere
			};

int intResult;
if (objTrans == null)
{ intResult = objDb.ExecuteNonQuery("tThiTotNghiepHocSinhDeleteWhere", parameters); }
else if (objTrans.Connection == null)
{ intResult = objDb.ExecuteNonQuery("tThiTotNghiepHocSinhDeleteWhere", parameters); }
else
{ intResult = objDb.ExecuteNonQuery(objTrans, "tThiTotNghiepHocSinhDeleteWhere", parameters); }
if (intResult > 0) return true;
}
catch { return false; }
return blnResult;
		}

		/// <summary>
		/// Selects a single record from the tThiTotNghiepHocSinh table.
		/// </summary>
		public static TThiTotNghiepHocSinhDTO Select(Database objDb, int tTN_ID, int hS_ID)
		{
try{
			object[] parameters = new object[]
			{
Null.GetNull(tTN_ID, DBNull.Value),
Null.GetNull(hS_ID, DBNull.Value)
			};

			using (IDataReader dataReader = objDb.ExecuteReader("tThiTotNghiepHocSinhSelect", parameters))
			{
				if(dataReader.FieldCount > 0)
				{
					return MapDataReader(dataReader);
				}
				else
				{
					return null;
				}
			}
}catch { return null; }
		}

		/// <summary>
		/// Selects a single record from the tThiTotNghiepHocSinh table.
		/// </summary>
		public static DataTable Select(Database objDb, int tTN_ID, int hS_ID, bool blnReturnDatatable = true)
		{
try{
			object[] parameters = new object[]
			{
Null.GetNull(tTN_ID, DBNull.Value),
Null.GetNull(hS_ID, DBNull.Value)
			};

			using (IDataReader dataReader = objDb.ExecuteReader("tThiTotNghiepHocSinhSelect", parameters))
			{
				if(dataReader.FieldCount > 0)
				{
				DataTable dt = new DataTable();
				dt.Load(dataReader);
					return dt;
				}
				else
				{
					return null;
				}
			}
}catch { return null; }
		}

		/// <summary>
		/// Get next index from the tThiTotNghiepHocSinh table.
		/// </summary>
		public static int SelectNextIndex(Database objDb)		{
int intResult = -1;
try{
IDataReader dr = objDb.ExecuteReader("tThiTotNghiepHocSinhSelectNextIndex");
if (dr != null)
{
DataTable dt = Untils.ConvertDataReaderToDataTable(dr, true);
intResult = clsCommon.fncCnvNullToInt(dt.Rows[0][0]);
}
}catch { }
return intResult;
		}

		/// <summary>
		/// Creates a new instance of the TThiTotNghiepHocSinhDTO class and populates it with data from the specified SqlDataReader.
		/// </summary>
		private static TThiTotNghiepHocSinhDTO MapDataReader(IDataReader dataReader)
		{
			TThiTotNghiepHocSinhDTO tThiTotNghiepHocSinhDTO = new TThiTotNghiepHocSinhDTO();
DataTable dt = new DataTable();
dt.Load(dataReader);
if (dt.Rows.Count <= 0) return tThiTotNghiepHocSinhDTO;
			tThiTotNghiepHocSinhDTO.TTN_ID = clsCommon.fncCnvNullToInt(dt.Rows[0]["TTN_ID"]);
			tThiTotNghiepHocSinhDTO.HS_ID = clsCommon.fncCnvNullToInt(dt.Rows[0]["HS_ID"]);

			return tThiTotNghiepHocSinhDTO;
		}
		/// <summary>
		/// Creates a new instance of the TThiTotNghiepHocSinhDTO class and populates it with data from the specified SqlDataReader.
		/// </summary>
		private static List<TThiTotNghiepHocSinhDTO> MapDataReaderList(IDataReader dataReader)
		{
				List<TThiTotNghiepHocSinhDTO> lstResult = new List<TThiTotNghiepHocSinhDTO>();
			TThiTotNghiepHocSinhDTO tThiTotNghiepHocSinhDTO;
DataTable dt = new DataTable();
dt.Load(dataReader);
for (int i = 0; i <= dt.Rows.Count-1; i++)
{
			tThiTotNghiepHocSinhDTO = new TThiTotNghiepHocSinhDTO();
			tThiTotNghiepHocSinhDTO.TTN_ID = clsCommon.fncCnvNullToInt(dt.Rows[i]["TTN_ID"]);
			tThiTotNghiepHocSinhDTO.HS_ID = clsCommon.fncCnvNullToInt(dt.Rows[i]["HS_ID"]);
lstResult.Add(tThiTotNghiepHocSinhDTO);
}

			return lstResult;
		}

		#endregion
	}
}
